//
//  TTIM_GroupUserCell.m
//  BaseProject
//
//  Created by 王洋 on 2020/10/12.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "TTIM_GroupUserCell.h"

@implementation TTIM_GroupUserCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)fillCellWithModel:(TGroupMemberCellData *)model {
    
    if (model.avatarImage) {
        self.userIcon.image = model.avatarImage;
    } else {
        self.userIcon.image = DefaultAvatarImage;
        [[V2TIMManager sharedInstance] getUsersInfo:@[model.identifier] succ:^(NSArray<V2TIMUserFullInfo *> *infoList) {
            if (infoList.firstObject) {
                [self.userIcon sd_setImageWithURL:[NSURL URLWithString:infoList.firstObject.faceURL] placeholderImage:DefaultAvatarImage];
            };
        } fail:nil];
    }

    if (model.name.length) {
        self.userName.text = model.name;
    } else {
        self.userName.text = model.identifier;
    }    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [self.userIcon pp_clipCorners:UIRectCornerAllCorners radius:self.userIcon.frame.size.height/2];
        
    });
}

@end
